//  https://www.nowcoder.com/questionTerminal/cf24906056f4488c9ddb132f317e03bc

#include<bits/stdc++.h>
using namespace std;
struct Postion
{
    int x;
    int y;
    Postion(int a,int b) :x(a),y(b)
    {}
};
stack<Postion> st;//保存沿途的路径
void Print()
{
    stack<Postion> rst;
    while(!st.empty())
    {
        rst.push(st.top());
        st.pop();
    }
    //输出
    while(!rst.empty())
    {
        printf("(%d,%d)\n",rst.top().x,rst.top().y);
        rst.pop();
    }
}
bool isPass(vector<vector<int>>& vv,Postion pos)
{
    int n = vv.size();
    int m = vv[0].size();
    if(pos.x >= 0 && pos.x<n && pos.y >=0 && pos.y < m && vv[pos.x][pos.y] == 0)
        return true;
    else
        return false;
}
bool GetPath(vector<vector<int>>& vv,Postion pos)
{
    st.push(pos);
    int n = vv.size();
    int m = vv[0].size();
    if(pos.x == n-1 && pos.y == m-1)
           return true;
    
    vv[pos.x][pos.y] = 2;
    //往上下左右位置进行搜索
    Postion nextUp{ pos.x - 1,pos.y };
    Postion nextDown{ pos.x + 1, pos.y };
    Postion nextLeft{ pos.x, pos.y - 1 };
    Postion nextRight{pos.x, pos.y + 1};
    
    if(isPass(vv,nextUp))
    {
        if(GetPath(vv, nextUp))
           return true;
    }
    if(isPass(vv,nextDown))
    {
        if(GetPath(vv, nextDown))
           return true;
    }
    if(isPass(vv,nextLeft))
    {
        if(GetPath(vv, nextLeft))
           return true;
    }
     if(isPass(vv,nextRight))
    {
        if(GetPath(vv, nextRight))
           return true;
    }
    st.pop();
    return false;
}
int main()
{
    int n,m;
   
    while(cin >> n >> m)
    {
        vector<vector<int>> vv(n,vector<int>(m));
        for(int i = 0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                cin >> vv[i][j];
            }
        }
        Postion start{0,0};
        if(GetPath(vv, start))
        {
            Print();
        }
    }
    return 0;
}